<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改购买记录')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-cardBuyLog-edit" th:object="${cardBuyLog}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>卡池名称：</label>
                <div class="col-sm-3">
                    <select name="cardId" class="form-control m-b">
                        <option
                                th:each="cardPool : ${cardPoolList}"
                                th:selected="*{cardId} eq ${cardPool.cardId}"
                                th:value="${cardPool['cardId']}"
                                th:text="${cardPool['cardName']}">
                        </option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>购买数量：</label>
                <div class="col-sm-8">
                    <input name="buyCount" th:field="*{buyCount}" class="form-control" type="text" maxlength="8" oninput="setValue()" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>预估余量：</label>
                <div class="col-sm-8">
                    <input name="predictRemainder" th:field="*{predictRemainder}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>实际余量：</label>
                <div class="col-sm-8">
                    <input name="actualRemainder" th:field="*{actualRemainder}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label"><span style="color: red; ">*</span>入库时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="putstockTime" th:value="${#dates.format(cardBuyLog.putstockTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">批次有效期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="batchValidityTime" th:value="${#dates.format(cardBuyLog.batchValidityTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "tencent/cardBuyLog";
        $("#form-cardBuyLog-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-cardBuyLog-edit').serialize());
            }
        }

        $("input[name='putstockTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='batchValidityTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        function setValue() {
            var buyCount = document.getElementById('buyCount').value; //获取第一个输入框的值
            if ($.common.isEmpty(buyCount)) {  //如果为非数字，结果为空
                document.getElementById('predictRemainder').value = "";
                document.getElementById('actualRemainder').value = "";
            } else {
                document.getElementById("predictRemainder").value = buyCount;
                document.getElementById("actualRemainder").value = buyCount;
            }
        }
    </script>
</body>
</html>